
import { _decorator, Component, Node, tween, v3 } from 'cc';
import BasePanel from '../../../core/component/BasePanel';
import WindowManager from '../../../core/manager/WindowManager';
import GameConst from '../../../core/common/GameConst';
import WXTTUtils from '../../../core/manager/WXTTUtils';
import Data from '../../../core/manager/Data';
import { Main } from '../Main';
import AudioMgr from '../../../core/utils/AudioMgr';
const { ccclass, property } = _decorator;

@ccclass('OutOfBoxLayer')
export class OutOfBoxLayer extends BasePanel {
    start() {
        let btn_clear = this.GetGameObject("btn_clear");
        tween(btn_clear).sequence(tween(btn_clear).to(1, { scale: v3(0.8, 0.8, 0.8) }), tween(btn_clear).to(1, { scale: v3(1, 1, 1) })).repeatForever().start()

        this.SetText("lbl_coll_star", Main.Instance()._GameUI.star + "");
        this.GetGameObject("one-more-chance-bg").active = false;

        Main.Instance()._GameUI.pasue = true;
        AudioMgr.Instance().playSFX('softFail')
    }

    onDestroy() {
        super.onDestroy();
        Main.Instance()._GameUI.pasue = false;
    }


    onBtnClicked(event: any, customEventData: any) {
        AudioMgr.Instance().playSFX('btnclick')
        var btnName = event.target.name;
        switch (btnName) {
            case "btn_close":
                if (this.GetGameObject("one-more-chance-bg").active == false && Main.Instance()._GameUI.star > 0) {
                    this.GetGameObject("one-more-chance-bg").active = true;
                    tween(this.GetGameObject("one-more-chance-bg")).to(1, { position: v3(0, 372, 0) }).start();
                    return
                }

                this.close();
                WindowManager.ins.open("FailLayer");
                break;
            case "btn_clear":
                WXTTUtils.showVideo((b) => {
                    if (b == 0) {
                        this.dispatch(GameConst.CLEAR_ALL_BOX);
                        this.close();
                    } else if (b == -2) {
                        WXTTUtils.share((bol) => {
                            if (bol) {
                                this.dispatch(GameConst.CLEAR_ALL_BOX);
                                this.close();
                            }
                        })
                    }
                })
                break;
        }
    }
}
